﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using System.Data.SQLite;
using System.IO;

namespace DataHandler {
    public class DataHandlerImplementation : IDataHandler {

        /// <summary>
        /// Connection für die Datenbank
        /// </summary>
        private SQLiteConnection con;

        /// <summary>
        /// Die Datenbank Properties
        /// </summary>
        private DataBaseProperties properties = DataBaseProperties.GetInstance();


        /// <summary>
        /// Konstruktor - Initialisiert das SQLite Connection Objekt
        /// </summary>
        public DataHandlerImplementation() {
            if (string.IsNullOrEmpty(this.properties.SQLiteDatabaseFile)) {
                this.properties.SQLiteDatabaseFile = Properties.Settings.Default.databasefile;
            }
            try {
                this.con = new SQLiteConnection(this.properties.ConnectionString);
                this.IsDatabaseConnected = true; 
            }
            catch {
                try {
                    this.properties.SQLiteDatabaseFile = Properties.Settings.Default.databasefile;
                    this.IsDatabaseConnected = true; 
                }
                catch {
                    IsDatabaseConnected = false;
                }
            }
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                if (checkAndOpenDb()) {
                    cmd.CommandText = "PRAGMA foreign_keys = ON;";
                    cmd.ExecuteNonQuery();
                }
            }
        }       

        /// <summary>
        /// Speichert eine SoundSuite in einer SQLite Datenbank. Die SoundSuite wird neu erstellt, wenn sie noch nicht vorhanden ist, ansonsten wird sie überschrieben
        /// </summary>
        /// <param name="suite"></param>
        public void SaveSoundSuite(SoundSuite suite) {
            if (checkAndOpenDb() && suite != null) {
                SQLiteCommand cmd = this.con.CreateCommand();

                SoundSuite currentSuite = this.LoadSoundSuite(suite.Id);
                List<EffectGroup> currentGroups = currentSuite != null ? currentSuite.EffectGroups : new List<EffectGroup>();


                if (dbContainsEntity(Entity.SoundSuite, suite.Id)) {
                    cmd.CommandText = "UPDATE SoundSuite SET Name = @name, Abenteuer = @adventure WHERE idSoundSuite = @id";
                }
                else {
                    cmd.CommandText = "INSERT INTO SoundSuite (idSoundSuite, Name, Abenteuer) VALUES (@id, @name, @adventure);";
                }
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = suite.Id.ToString();
                cmd.Parameters.Add("@name", System.Data.DbType.String).Value = suite.Name;
                cmd.Parameters.Add("@adventure", System.Data.DbType.String).Value = suite.Adventure;
                cmd.ExecuteNonQuery();



                foreach (EffectGroup group in currentGroups) {
                    if (!suite.EffectGroups.Contains(group)) {
                        SQLiteCommand cmdDelete = this.con.CreateCommand();
                        cmdDelete.CommandText = "DELETE FROM effektGroup WHERE idEffektGroup = @id";
                        cmdDelete.Parameters.Add("@id", System.Data.DbType.String).Value = group.ID;
                        cmdDelete.ExecuteNonQuery();
                    }
                }
                foreach (EffectGroup group in suite.EffectGroups) {
                    this.SaveEffectGroup(group);
                }
            }
        }
        

        /// <summary>
        /// Löscht eine SoundSuite mit all den dazugehörigen Elementen aus der Datenbank
        /// </summary>
        /// <param name="id"></param>
        public void DeleteSoundSuite(Guid id) {
            SQLiteCommand cmd = this.con.CreateCommand();
            cmd.CommandText = "DELETE FROM SoundSuite WHERE idSoundSuite = @id";
            cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
            cmd.ExecuteNonQuery();
        }

        /// <summary>
        /// Überprüft, ob eine Entität mit der angegebenen ID schon vorhanden ist
        /// </summary>
        /// <param name="entityType">Der Entitäts Typ</param>
        /// <param name="id">Die ID des Objektes</param>
        /// <returns></returns>
        private bool dbContainsEntity(Entity entityType, Guid id) {
            SQLiteCommand cmd = this.con.CreateCommand();
            switch (entityType) {
                case Entity.SoundSuite:
                    cmd.CommandText = "SELECT COUNT(*) FROM SoundSuite WHERE IdSoundSuite = @id";
                    break;
                case Entity.EffectGroup:
                    cmd.CommandText = "SELECT COUNT(*) FROM effektGroup WHERE idEffektGroup = @id";
                    break;
                case Entity.Effect:
                    cmd.CommandText = "SELECT COUNT(*) FROM effekt WHERE IdEffekt = @id";
                    break;
                case Entity.Track:
                    cmd.CommandText = "SELECT COUNT(*) FROM track WHERE IdTrack = @id";
                    break;
                case Entity.Category:
                    cmd.CommandText = "SELECT COUNT(*) FROM category WHERE idCategory = @id";
                    break;                
            }
            cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id.ToString();
            return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
        }

        /// <summary>
        /// überprüpft, ob die Datenbank Verbindung offen ist und öffnet sie gegebenenfalls
        /// </summary>
        /// <returns></returns>
        private bool checkAndOpenDb() {
            
            if (this.con.State != System.Data.ConnectionState.Open) {
                this.con.Open();
            }
            return this.con.State == System.Data.ConnectionState.Open;
        }

        /// <summary>
        /// Lädt eine SoundSuite mit all ihren Groups und Effects und Tracks
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SoundSuite LoadSoundSuite(Guid id) {
            SoundSuite returnValue = null;

            if (this.checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();
                cmd.CommandText = "SELECT idSoundSuite, Name, Abenteuer FROM SoundSuite WHERE idSoundSuite = @id";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;

                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    if (reader.Read()) {
                        returnValue = new SoundSuite(reader.GetString(1));
                        returnValue.Id = reader.GetGuid(0);
                        returnValue.Adventure = reader.GetString(2);
                    }
                }

                cmd.CommandText = "SELECT idEffektGroup FROM effektGroup WHERE SoundSuite = @id;";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;

                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    while (reader.Read()) {
                        returnValue.EffectGroups.Add(this.LoadEffectGroup(reader.GetGuid(0)));
                    }
                }
            }
            return returnValue;
        }


        /// <summary>
        /// Diese Methode gibt eine LIste mit allen SoundSuites zurück
        /// </summary>
        /// <returns></returns>
        public List<SoundSuite> ShowSoundSuites() {
            List<SoundSuite> returnList = new List<SoundSuite>();
            if (checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();
                cmd.CommandText = "SELECT idSoundSuite FROM SoundSuite";
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    while (reader.Read()) {
                        returnList.Add(this.LoadSoundSuite(reader.GetGuid(0)));
                    }
                }
            }
            return returnList;
        }

        /// <summary>
        /// Lädt eine EffectGroup anhand einer ID
        /// </summary>
        /// <param name="id"></param>
        public EffectGroup LoadEffectGroup(Guid id) {
            EffectGroup group = null;
            if (checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();
                cmd.CommandText = "SELECT idEffektGroup, name, key, soundSuite  FROM effektGroup WHERE idEffektGroup = @id;";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    if (reader.Read()) {
                        group = new EffectGroup();
                        group.ID = reader.GetGuid(0);
                        group.Name = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        group.Key = reader.IsDBNull(2) ? default(char) : reader.GetString(2).FirstOrDefault();
                        Guid outId;
                        group.ParentID = Guid.TryParse(reader.GetString(3), out outId) ? outId : Guid.Empty;
                    }
                }

                cmd.CommandText = "SELECT idEffekt FROM Effekt WHERE effektGroup = @id;";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    while (reader.Read()) {
                        Effect e = LoadEffect(reader.GetGuid(0));
                        group.Effects.Add(e.Key, e);
                    }
                }
            }
            return group;
        }

        /// <summary>
        /// Speichert eine mitgegebene EffectGroup in der Datenbank.
        /// </summary>
        /// <param name="group">EffectGroup, welche gespeicert werden soll</param>
        public void SaveEffectGroup(Foundation.EffectGroup group) {
            if (checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();

                Dictionary<char, Effect> currentEffects = this.LoadEffectGroup(group.ID) == null ? new Dictionary<char, Effect>() : this.LoadEffectGroup(group.ID).Effects;

                if (dbContainsEntity(Entity.EffectGroup, group.ID)) {
                    cmd.CommandText = "UPDATE effektGroup SET name = @name, key = @key, SoundSuite = @suite WHERE idEffektGroup = @id;";
                }
                else {
                    cmd.CommandText = "INSERT INTO effektGroup (ideffektGroup, name, key, SoundSuite) VALUES (@id, @name, @key, @suite);";
                }
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = group.ID.ToString();
                cmd.Parameters.Add("@name", System.Data.DbType.String).Value = group.Name;
                cmd.Parameters.Add("@key", System.Data.DbType.String).Value = group.Key.ToString();
                cmd.Parameters.Add("@suite", System.Data.DbType.String).Value = group.ParentID;
                cmd.ExecuteNonQuery();


                foreach (KeyValuePair<char, Effect> pair in currentEffects) {
                    if (!group.Effects.Values.Contains(pair.Value)) {
                        this.DeleteEffect(pair.Value.Id);
                    }
                }

                if (group.Effects.Any()) {
                    foreach (Effect e in group.Effects.Values) {
                        this.SaveEffect(e);
                    }
                }
            }
        }

        /// <summary>
        /// Löscht einen Effect aus der Datenbank
        /// </summary>
        /// <param name="guid"></param>
        private void DeleteEffect(Guid guid) {
            SQLiteCommand cmd = this.con.CreateCommand();
            cmd.CommandText = "DELETE FROM effekt WHERE idEffekt = @id";
            cmd.Parameters.Add("@id", System.Data.DbType.String).Value = guid;
            cmd.ExecuteNonQuery();
        }

        /// <summary>
        /// Diese Methode lädt einen Effect anhand einer ID mit allen seinen Tracks aus der Datenbank
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Foundation.Effect LoadEffect(Guid id) {
            Effect effect = null;
            if (this.checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();
                cmd.CommandText = "SELECT * FROM effekt WHERE idEffekt = @id";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    if (reader.Read()) {
                        effect = new Effect();
                        effect.Id = reader.GetGuid(0);
                        effect.Name = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        effect.Key = reader.IsDBNull(2) ? default(char) : reader.GetString(2).FirstOrDefault();
                        effect.Type = (EffectTypeEnum)reader.GetInt32(3);
                        effect.Volume = reader.GetInt32(4);
                        effect.ParentId = reader.GetGuid(5);
                    }
                }
                if (effect != null) {
                    cmd.CommandText = "SELECT track.idTrack, track.name, track.path FROM TrackInEffekt LEFT JOIN TRACK ON TRackInEffekt.TrackId = track.idTrack WHERE trackInEffekt.effektId = @id";
                    cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                    using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                        while (reader.Read()) {
                            effect.Tracks.Add(new Track(reader.GetString(1), reader.GetString(2), reader.GetString(0)));
                        }
                    }
                }
            }
            return effect;
        }


        /// <summary>
        /// Speichert einen mitgegebenen Effect auf der Datenbank.
        /// </summary>
        /// <param name="effect"></param>
        public void SaveEffect(Effect effect) {
            if (checkAndOpenDb()) {
                SQLiteCommand cmd = this.con.CreateCommand();

                List<Track> currentTracks = this.LoadEffect(effect.Id) == null ? new List<Track>() : this.LoadEffect(effect.Id).Tracks;

                if (dbContainsEntity(Entity.Effect, effect.Id)) {
                    cmd.CommandText = "UPDATE effekt SET effektName =  @name, key = @key, effektArt = @art, volume = @volume, effektGroup = @group WHERE ideffekt = @id;";
                }
                else {
                    cmd.CommandText = "INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (@id, @name, @key, @art, @volume, @group);";
                }

                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = effect.Id;
                cmd.Parameters.Add("@name", System.Data.DbType.String).Value = effect.Name;
                cmd.Parameters.Add("@key", System.Data.DbType.String).Value = effect.Key.ToString();
                cmd.Parameters.Add("@art", System.Data.DbType.Int32).Value = effect.Type;
                cmd.Parameters.Add("@volume", System.Data.DbType.Int32).Value = effect.Volume;
                cmd.Parameters.Add("@group", System.Data.DbType.String).Value = effect.ParentId;
                cmd.ExecuteNonQuery();


                cmd.CommandText = "DELETE FROM TrackInEffekt WHERE effektId = @effektId";
                cmd.Parameters.Add("@effektId", System.Data.DbType.String).Value = effect.Id;
                cmd.ExecuteNonQuery();

                if (effect.Tracks.Any()) {
                    cmd.CommandText = "INSERT INTO trackInEffekt(EffektId, TrackId) Values (@effektId, @TrackId); ";
                    foreach (Track t in effect.Tracks) {
                        cmd.Parameters.Add("@effektId", System.Data.DbType.String).Value = effect.Id;
                        cmd.Parameters.Add("@TrackId", System.Data.DbType.String).Value = t.Id;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }


        #region Track Methods

        /// <summary>
        /// Schreibt eine Liste mit Tracks in die Datenbank.
        /// </summary>
        /// <param name="tracks">Eine Liste mit den Tracks, welche abgefüllt werden sollen</param>
        /// <exception cref="FileNameNotValidException"></exception>
        /// <exception cref="NullReferenceException"></exception>
        public void FillTracks(List<Track> tracks) {
            List<string> notValidFiles = new List<string>();
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                cmd.CommandText = "INSERT INTO TRACK (idtrack, path, name) VALUES (@id, @path, @name);";
                foreach (Track t in tracks) {
                    if (File.Exists(t.FullPath)) {
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add("@id", System.Data.DbType.String).Value = t.Id;
                        cmd.Parameters.Add("@path", System.Data.DbType.String).Value = t.Path;
                        cmd.Parameters.Add("@name", System.Data.DbType.String).Value = t.Name;
                        cmd.ExecuteNonQuery();
                    }
                    else {
                        notValidFiles.Add(t.FullPath);
                    }
                }
            }
            if (notValidFiles.Any()) {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Folgende Tracks konnten nicht importiert werden:");
                foreach (string s in notValidFiles) {
                    sb.AppendLine(s);
                }
                throw new FileNameNotValidException(sb.ToString(), null);
            }
        }

        /// <summary>
        /// Gibt eine Liste mit allen Tracks in der Datenbank zurück, welche noch keiner Kategorie 
        /// zugewiesen sind.
        /// </summary>
        /// <returns></returns>
        public List<Foundation.Track> ShowUnassignedTracks() {
            List<Track> returnList = new List<Track>();
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                cmd.CommandText = "SELECT idTrack, path, name FROM track WHERE idTrack not in (SELECT trackId from trackInCategorie);";
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    while (reader.Read()) {
                        Track t = new Track(
                            reader.IsDBNull(2) ? string.Empty : reader.GetString(2),
                            reader.IsDBNull(1) ? string.Empty : reader.GetString(1));
                        t.Id = reader.GetGuid(0);
                        returnList.Add(t);
                    }
                }
            }
            return returnList;
        }

        /// <summary>
        /// Schreibt einen Track in die Datenbank, wenn er noch nicht vorhanden ist, ansonsten wird 
        /// er aktualisiert.
        /// </summary>
        /// <param name="t"></param>
        private void saveTrack(Track t) {
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                if (this.dbContainsEntity(Entity.Track, t.Id)) {
                    cmd.CommandText = "UPDATE TRACK SET path = @path, name = @name WHERE idtrack = @id;";
                }                
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = t.Id;
                cmd.Parameters.Add("@path", System.Data.DbType.String).Value = t.Path;
                cmd.Parameters.Add("@name", System.Data.DbType.String).Value = t.Name;
                cmd.ExecuteNonQuery();
            }
        }

        #endregion

        #region Category Methods

        /// <summary>
        /// Weisst einen Track einer Kategorie zu.
        /// </summary>
        /// <param name="trackId"></param>
        /// <param name="CategoryId"></param>
        public void AssignTracks(Guid trackId, Guid CategoryId) {
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                if (!dbContainsEntity(Entity.Category, CategoryId)) {
                    throw new CategoryNotExistException(
                        string.Format("Die Kategorie mit der ID {0} ist nicht in der Datenbank vorhanden",
                        trackId.ToString()), null);
                }
                else if (!dbContainsEntity(Entity.Track, trackId)) {
                    throw new TrackNotExistException(
                        string.Format("Ein Track mit der ID {0} ist nicht in der Datenbank vorhanden",
                        trackId), null);
                }
                else if (isTrackAlreadyAssigned(trackId, CategoryId)) {
                    throw new TrackAlreadyAssignedException(string.Format("Der Track {0} ist bereits der Kategorie {1} zugewiesen",
                        trackId, CategoryId), null);
                }
                else {
                    cmd.CommandText = "INSERT INTO trackInCategorie (trackId, categoryId) VALUES (@trackId, @categoryId);";
                    cmd.Parameters.Add("@trackId", System.Data.DbType.String).Value = trackId;
                    cmd.Parameters.Add("@categoryId", System.Data.DbType.String).Value = CategoryId;
                    cmd.ExecuteNonQuery();
                }
            }
        }

        /// <summary>
        /// Gibt zurück, ob ein Track bereits einer Kategorie zugewiesen wurde.
        /// </summary>
        /// <param name="trackId">ID des Tracks</param>
        /// <param name="CategoryId">ID der Kategorie</param>
        /// <returns></returns>
        private bool isTrackAlreadyAssigned(Guid trackId, Guid CategoryId) {
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                cmd.CommandText = "SELECT Count(*) FROM trackInCategorie WHERE trackId = @trackId AND categoryId = @categoryId;";
                cmd.Parameters.Add("@trackId", System.Data.DbType.String).Value = trackId;
                cmd.Parameters.Add("@categoryId", System.Data.DbType.String).Value = CategoryId;
                return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
            }
        }

        /// <summary>
        /// Speichert eine Kategorie und die dazugehörigen Tracks
        /// </summary>
        /// <param name="category"></param>
        public void SaveCategory(Category category) {
            if (checkAndOpenDb()) {
                using (SQLiteCommand cmd = this.con.CreateCommand()) {
                    if (!this.dbContainsEntity(Entity.Category, category.ID)) {
                        cmd.CommandText = "INSERT INTO category (idCategory, name) VALUES (@id, @name);";
                    }
                    else {
                        cmd.CommandText = "UPDATE category set name = @name WHERE  idCategory = @id;";
                    }
                    cmd.Parameters.Add("@id", System.Data.DbType.String).Value = category.ID;
                    cmd.Parameters.Add("@name", System.Data.DbType.String).Value = category.Name;
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "DELETE FROM trackInCategorie WHERE categoryId = @catId";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@catId", System.Data.DbType.String).Value = category.ID;
                    cmd.ExecuteNonQuery();

                    foreach (Track t in category.Tracks) {
                        if (!this.isTrackAlreadyAssigned(t.Id, category.ID)) {
                            this.AssignTracks(t.Id, category.ID);
                        }
                        this.saveTrack(t);
                    }
                }
            }
        }

        /// <summary>
        /// Löscht eine Category aus der Datenbank und all die Track Zuweisungen.
        /// </summary>
        /// <param name="categoryId"></param>
        public void DeleteCategory(Guid categoryId) {
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                cmd.CommandText = "DELETE FROM category WHERE idCategory = @id";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = categoryId;
                cmd.ExecuteNonQuery();
            }
        }

        /// <summary>
        /// Gibt eine Category anhand einer ID zurück inklusive dazugehörige Tracks
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Category LoadCategory(Guid id) {
            Category returnValue = null;
            using (SQLiteCommand cmd = this.con.CreateCommand()) {
                cmd.CommandText = "SELECT idCategory, name from Category WHERE idCategory = @id";
                cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                    if (reader.Read()) {
                        string name = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        returnValue = new Category(name);
                        returnValue.ID = reader.GetGuid(0);
                    }
                }
                if (returnValue != null) {
                    cmd.Parameters.Clear();
                    cmd.CommandText = "SELECT CategoryId, trackId, path, name FROM trackInCategorie LEFT JOIN track on trackIncategorie.trackId = track.idTrack WHERE categoryId = @id";
                    cmd.Parameters.Add("@id", System.Data.DbType.String).Value = id;
                    using (SQLiteDataReader reader = cmd.ExecuteReader()) {
                        while (reader.Read()) {
                            string name = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
                            string path = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
                            string trackId = reader.GetString(1);
                            returnValue.Tracks.Add(new Track(name, path, trackId));
                        }
                    }
                }
                return returnValue;
            }
        #endregion

        }

        /// <summary>
        /// Mit dieser Methode kann ein ConnectionString für die Verbindung zur Datenbank gesetzt werden.
        /// </summary>
        /// <param name="conString">Der Connection String</param>
        /// <param name="dbType">Der Datenbank Typ</param>
        /// <exception cref="InvalidDatebaseException"></exception>
        public void SetConnectionString(string conString, DataBaseType dbType) {
            SQLiteConnectionStringBuilder cb = new SQLiteConnectionStringBuilder(conString);

            if (File.Exists(cb.DataSource)) {
                this.con = new SQLiteConnection(conString);
            }
            else {
                throw new InvalidDatebaseException("Das angegebene Datenbank File ist nicht vorhanden", null);
            }
        }

        /// <summary>
        /// Zeigt an, ob auf die Datenbank verbunden werden konnte
        /// </summary>
        public bool IsDatabaseConnected {
            get;
            private set;
        }
        
    }
}